package com.example.mountainwalker.service.impl;

import com.example.mountainwalker.entity.RegionInfo;
import com.example.mountainwalker.mapper.RegionMapper;
import com.example.mountainwalker.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    private RegionMapper regionMapper;

    @Override
    public List<RegionInfo> getAllRegions() {
        return regionMapper.getAllRegions();
    }

    @Override
    public RegionInfo getRegionById(Integer regionId) {
        return regionMapper.getRegionById(regionId);
    }

    @Override
    public int insertRegion(RegionInfo regionInfo) {
        return regionMapper.insertRegion(regionInfo);
    }

    @Override
    public int updateRegion(RegionInfo regionInfo) {
        return regionMapper.updateRegion(regionInfo);
    }

    @Override
    public int deleteRegion(Integer regionId) {
        return regionMapper.deleteRegion(regionId);
    }

    @Override
    public List<RegionInfo> searchByProvince(String province) {
        if (province == null || province.trim().isEmpty()) {
            return getAllRegions();
        }
        return regionMapper.searchByProvince(province);
    }

    @Override
    public List<RegionInfo> searchByCity(String city) {
        if (city == null || city.trim().isEmpty()) {
            return getAllRegions();
        }
        return regionMapper.searchByCity(city);
    }
}